from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime

class ScheduleBase(BaseModel):
    spider_id: str = Field(..., description="关联的爬虫ID")
    cron_expression: str = Field(..., description="CRON表达式")
    description: Optional[str] = Field(None, description="定时任务描述")
    enabled: bool = Field(True, description="是否启用")

class ScheduleCreate(ScheduleBase):
    pass

class ScheduleUpdate(BaseModel):
    cron_expression: Optional[str] = Field(None, description="CRON表达式")
    description: Optional[str] = Field(None, description="定时任务描述")
    enabled: Optional[bool] = Field(None, description="是否启用")

class ScheduleRead(ScheduleBase):
    id: str = Field(..., description="定时任务唯一标识符")
    created_at: datetime = Field(..., description="创建时间")
    updated_at: datetime = Field(..., description="最后更新时间")
    last_run_at: Optional[datetime] = Field(None, description="上次运行时间")
    next_run_at: Optional[datetime] = Field(None, description="下次计划运行时间")
    
    class Config:
        orm_mode = True